<template>
  <div id="add">
     <el-form 
      :model="addForm" 
      class="demo-form-inline"
      label-width="80px"
      label-position="top"
      :rules="rules"
      ref="addForm"
      >
        <el-form-item label="管理员" prop="name">
          <el-input v-model="addForm.name1" autocomplete="off" clearable></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input v-model="addForm.pass1" type="password"></el-input>
        </el-form-item>
        <el-form-item label="权限管理">
          <el-checkbox label="发表权限" v-model="addForm.allowPublish"></el-checkbox>
          <el-checkbox label="修改权限" v-model="addForm.allowUpdate"></el-checkbox>
          <el-checkbox label="删除权限" v-model="addForm.allowDelete"></el-checkbox>
      </el-form-item>
      </el-form>
      <el-button type="primary" @click="submit">添加管理员</el-button>
  </div>
</template>
 
<script>
export default {
  name: 'Addadministrator',
  data(){
    return{
      addForm:{
        name1:"",
        pass1:"",
        allowDelete:false,
        allowPublish:false,
        allowUpdate:false
      },
      rules:{
        name:[
        ],
        pass:[
        ]
      }
    }
  },
  methods:{
    // 添加管理员
    submit(){
      this.$refs.addForm.validate(async v=>{
        if(!v) return false
        let {data} = await this.$axios.post("/admin/administrators/reg",{
          name:this.addForm.name1,
          pass:this.addForm.pass1,
          allowDelete:this.addForm.allowDelete,
          allowPublish:this.addForm.allowPublish,
          allowUpdate:this.addForm.allowUpdate
        })
        if(data.code) return this.$message.warning(data.mes)
        this.$message.success(data.mes)
        // 清空表单
        this.$refs.addForm.resetFields()
        this.addForm.allowDelete = false
        this.addForm.allowPublish = false
        this.addForm.allowUpdate = false
      })
    }
  }
}
</script>

<style scoped lang='less'>
</style>